/**
 * 
 */
package com.googlecode.pcapj.bridj;

import org.bridj.Pointer;
import org.bridj.StructObject;
import org.bridj.ann.Field;

/**
	u_char	ver_ihl;		// Version (4 bits) + Internet header length (4 bits)
	u_char	tos;			// Type of service 
	u_short tlen;			// Total length 
	u_short identification; // Identification
	u_short flags_fo;		// Flags (3 bits) + Fragment offset (13 bits)
	u_char	ttl;			// Time to live
	u_char	proto;			// Protocol
	u_short crc;			// Header checksum
	ip_address	saddr;		// Source address
	ip_address	daddr;		// Destination address
 */
public class ip_header extends StructObject {
    public ip_header() { super(); }
    public ip_header(Pointer<? extends StructObject> pointer) { super(pointer); }

    /**
     * 
     * @return
     */
    @Field(0) 
    public byte vers_ihl() {
        return this.io.getByteField(this, 0);
    }
    
    /**
     * 
     * @param vers_ihl
     * @return
     */
    @Field(0) 
    public ip_header vers_ihl(byte vers_ihl) {
        this.io.setByteField(this, 0, vers_ihl);
        return this;
    }
    
    /**
     * @return
     */
    @Field(1) 
    public byte tos() {
            return this.io.getByteField(this, 1);
    }
    /**
     * @param tos
     * @return
     */
    @Field(1) 
    public ip_header tos(byte tos) {
            this.io.setByteField(this, 1, tos);
            return this;
    }
    
    /**
     * @return
     */
    @Field(2) 
    public short tlen() {
            return this.io.getShortField(this, 2);
    }
    /**
     * @param tos
     * @return
     */
    @Field(2) 
    public ip_header tlen(short tlen) {
            this.io.setShortField(this, 2, tlen);
            return this;
    }

    /**
     * @return
     */
    @Field(3) 
    public short identification() {
            return this.io.getShortField(this, 3);
    }
    /**
     * @param tos
     * @return
     */
    @Field(3) 
    public ip_header identification(short identification) {
            this.io.setShortField(this, 3, identification);
            return this;
    }
    
    /**
     * @return
     */
    @Field(4) 
    public short flags_fo() {
            return this.io.getShortField(this, 4);
    }
    /**
     * @param tos
     * @return
     */
    @Field(4) 
    public ip_header flags_fo(short flags_fo) {
            this.io.setShortField(this, 4, flags_fo);
            return this;
    }
    
    /**
     * @return
     */
    @Field(5) 
    public byte ttl() {
            return this.io.getByteField(this, 5);
    }
    /**
     * @param tos
     * @return
     */
    @Field(5) 
    public ip_header ttl(byte ttl) {
            this.io.setByteField(this, 5, ttl);
            return this;
    }
    
    /**
     * @return
     */
    @Field(6) 
    public byte proto() {
            return this.io.getByteField(this, 6);
    }
    /**
     * @param tos
     * @return
     */
    @Field(6) 
    public ip_header proto(byte proto) {
            this.io.setByteField(this, 6, proto);
            return this;
    }
    
    /**
     * @return
     */
    @Field(7) 
    public short crc() {
            return this.io.getShortField(this, 7);
    }
    /**
     * @param tos
     * @return
     */
    @Field(7) 
    public ip_header crc(short crc) {
            this.io.setShortField(this, 7, crc);
            return this;
    }
    
    /**
     * @return
     */
    @Field(8) 
    public ip_address saddr() {
            return this.io.getNativeObjectField(this, 8);
    }
    /**
     * @param tos
     * @return
     */
    @Field(8) 
    public ip_header saddr(ip_address saddr) {
            this.io.setNativeObjectField(this, 8, saddr);
            return this;
    }
    
    /**
     * @return
     */
    @Field(9) 
    public ip_address daddr() {
            return this.io.getNativeObjectField(this, 9);
    }
    /**
     * @param tos
     * @return
     */
    @Field(9) 
    public ip_header daddr(ip_address daddr) {
            this.io.setNativeObjectField(this, 9, daddr);
            return this;
    }
    /**
     * Gets length of internet header. 
     * @return 
     */
    public int getInternetHeaderLength(){
    	return 0xf & vers_ihl();
    }
}
